<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="Beans.CancelOrder"%>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="DaosImpl.OrderDaoImpl" import="DaosImpl.RoomDaoImpl" %>
<html>
	<%
		String path = request.getContextPath();
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
	 %>
  <head>
   <meta charset="UTF-8">
    <title>退房管理</title>
    <link href=<%=basePath+"/stylesheets/cancelOrder.css"%> type="text/css" rel="stylesheet">
    <style>
        html,body{
            height: 100%;
            margin:0;
            padding: 0;
        }
    </style>

  </head>
  
  <body>
    <div id="themeText">酒店退房管理</div>
	<div id="showRoomFrame">
		<table cellpadding="0" cellspacing="0">
        <thead>
        <tr>
            <th>订单编号</th>
            <th>顾客姓名</th>
            <th>身份证</th>
            <th>房号</th>
            <th>需交金额</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="mainbody">
	        <%
	        	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
	        	String date = simpleDateFormat.format(new Date()).toString();
	      		Date s = simpleDateFormat.parse(date);
	        	ArrayList<CancelOrder> list = null;
	        	OrderDaoImpl cancelDao = new OrderDaoImpl();
	        	list = cancelDao.queryAllCancelOrder();
	        	float money = 0;
	        	RoomDaoImpl roomDao = new RoomDaoImpl();
	        	for(int i = 0;i<list.size();i++){
	        		money = roomDao.getRoomOneRent(list.get(i).getRoomId());
	        		Date f = simpleDateFormat.parse(list.get(i).getInDate());
	        		int n = (int)((s.getTime()-f.getTime())/(24*60*60*1000));
	        		float totalMoney = money*n;
	        		float needPayMoney = totalMoney-list.get(i).getPayMoney();
	        		int roomid = list.get(i).getRoomId();
	        		int ofid = list.get(i).getOrderId();
	        		%>
	        		<tr id="delCell">
				            <td width="15%"><%=list.get(i).getOrderId() %></td>
				            <td width="15%"><%=list.get(i).getName() %></td>
				            <td width="15%"><%=list.get(i).getIdCard() %></td>
				            <td width="15%"><%=list.get(i).getRoomId() %></td>
				            <td width="15%"><%=needPayMoney%></td>
				            <td width="15%">
		                	<button style="padding: 5px 15px;border: 1px solid red;border-radius: 5px;background-color: red" onclick="cancel(this.value,<%=roomid%>,<%=ofid %>,<%=needPayMoney %>)" name="<%="btn"+i%>" value="<%=i%>">
		                    	退房
		            		</button>
		            		<script>
		            			function cancel(value,roomid,ofid,needPayMoney){
		            				var url = "http://localhost:8080/HotelSystem/Servlets/OutHomeServlet";
		            				var date = '<%=date%>';
		            				var money = parseInt(needPayMoney);
		            				if(money>0){
		            					if(prompt('请输入还需要缴纳金额',needPayMoney)==needPayMoney){
				            				alert("退房成功！");
				            				url = url+"?outdate="+date+"&roomid="+roomid+"&ofId="+ofid;
				            				url = decodeURI(decodeURI(url));
			            					location.href=url;
		            					}else{
		            						alert("退房失败！");
		            					}
		            				}else{
		            					money = -money;
		            					if(prompt('请输入结账给用户的金额',money)==money){
			            					alert("退房成功！");
				            				url = url+"?outdate="+date+"&roomid="+roomid+"&ofId="+ofid;
				            				url = decodeURI(decodeURI(url));
				            				location.href=url;
		            					}else{
		            						alert("退房失败！");
		            					}
		            				}
		            			}
		            		</script>
		            		</td>
	        		</tr>
	        		<%
	        	}
	        %>
        </tbody>
    </table>
 	</div>
  </body>
</html>
